import Vue from 'vue'
import VueRouter from 'vue-router'

// 导入需要的组件
// import MusicPlay from '@/components/MusicPlay.vue'
// 用户
// 登录注册
import UserLogin from '@/views/User/UserLogin.vue'
import UserRegister from '@/views/User/UserRegister.vue'
//发现音乐
import FindMusic from '@/views/Music/FindMusic.vue'
// 我的
import UserInfo from '@/views/User/UserInfo/UserInfo.vue'

// 修改密码
import UpdatePassword from '@/views/User/UserInfo/UpdatePassword.vue'
// 上传音乐
// import UploadMusic from '@/components/UploadMusic.vue'

import UserUploadMusic from '@/views/Music/upload/UserUploadMusic.vue'


// 修改音乐
import UserUpdateMusic from '@/views/Music/upload/UserUpdateMusic.vue'

// 我的作品
import Myproduction from '@/views/User/production/Myproduction.vue'

// 音乐故事
import UploadBlog from '@/views/blog/uploadBlog.vue'
import BlogList from '@/views/blog/BlogList.vue'
import BlogAllInfo from '@/views/blog/BlogAllInfo.vue'
import Music2BlogList from '@/views/blog/Music2BlogList.vue'
import User2BlogList from '@/views/blog/User2BlogList.vue'

// 推荐页面
import MusicRecPage from '@/views/Music/recommendationPage/MusicRecPage.vue'

// 音乐
// 音乐主页home
import MusicHome from '@/views/Music/MusicHome.vue'
// 音乐详细信息
import MusicAllInfo  from '@/views/Music/info/MusicAllInfo.vue'

// 用户收藏夹
import UserCollect  from '@/views/User/collect/UserCollect.vue'
// 用户评论音乐 
import MusicComment from '@/views/Music/info/comment/MusicComment.vue'
// 用户详细信息
import MyInfo from '@/views/User/UserInfo/MyInfo.vue'

// 修改用户详细信息
import UpdateInfo from '@/views/User/UserInfo/UpdateInfo.vue'


// 关注
import MyFollow  from '@/views/User/follow/MyFollow.vue'


// 音乐


// 把 VueRouter 安装为 Vue 的插件
Vue.use(VueRouter)

// 路由规则的数组
const routes = [
   // 定义首页的路由规则
  //  { path: '/',component: MusicPlay },
   { path: '/userLogin', component: UserLogin},
   { path: '/userRegister', component: UserRegister},
   { path: '/myInfo', component: MyInfo, meta: { isAuth: true }},
   { path: '/updateInfo', component: UpdateInfo, meta: { isAuth: true }},
   
  //  UpdatePassword
  { path: '/updatePassword', component: UpdatePassword, meta: { isAuth: true }},

   { path: '/findMusic', component: FindMusic },
   { path: '/userInfo', component: UserInfo , meta: { isAuth: true }},
   { path: '/userUploadMusic', component: UserUploadMusic },
   { path: '/userUpdateMusic', name:'userUpdateMusic',component: UserUpdateMusic },
   
  //  { path: '/userUpdateMusic', component: UserUpdateMusic },
   { path: '/userCollect', component: UserCollect},


   {path: '/myproduction',component: Myproduction},

   { path: '/musicHome', component: MusicHome },
   { path: '/musicComment', component:  MusicComment },

   { path: '/musicAllInfo',name:'musicAllInfo' ,component: MusicAllInfo },
   

  //  UploadBlog
  { path: '/uploadBlog',name:'uploadBlog' ,component: UploadBlog },
  // BlogList 
  { path: '/blogList',name:'blogList' ,component: BlogList },
  // Music2BlogList
  { path: '/music2BlogList',name:'music2BlogList' ,component: Music2BlogList },
  // User2BlogList
  { path: '/user2BlogList',name:'user2BlogList' ,component: User2BlogList },


  // BlogAllInfo
  { path: '/blogAllInfo',name:'blogAllInfo' ,component: BlogAllInfo },


  // MusicRecPage 
  { path: '/musicRecPage',name:'musicRecPage' ,component: MusicRecPage  },

  // MyFollow
  { path: '/myFollow',name:'myFollow ' ,component: MyFollow , meta: { isAuth: true }},

]

// 创建路由实例对象
const router = new VueRouter({
  routes
})

router.beforeEach((to,from,next)=>{
  next()
  // 如果路由需要跳转
  if (to.meta.isAuth) {
    //判断 如果已经登录有token，可以进去
    if(localStorage.getItem('token') != null && localStorage.getItem('token') != ""){
      next()  //放行
    }else{  
      next('/userLogin')
    }
  }else{
    // 无需要守卫
    next()
  }
})

export default router